package homework007.dao;

import homework007.domain.Goods;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 商品DAO
 *
 * @author itheima
 */
public class GoodsDao {
    private List<Goods> goodList = new ArrayList<>();

    public boolean add(Goods goods) {
        return goodList.add(goods);
    }

    public boolean deleteByIndex(int index) {
        Goods goods = goodList.remove(index);
        return Objects.nonNull(goods);
    }

    public boolean update(int index, Goods goods) {
        Goods goodsUpdated = goodList.set(index, goods);
        return Objects.nonNull(goodsUpdated);
    }

    public List<Goods> findAll() {
        return goodList;
    }
}
